﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using BreakOutBattles.ParticleSystems;
#endregion

namespace BreakOutBattles.Game.Items
{
    public class SmokeBrick : Brick
    {
        #region Fields
        private const int MAX_SMOKE_TIME = 3000;

        private int defaultResistance = 100;
        private int currentTime = 0;
        private int timeIncFactor = 1;

        private SmokePlumeParticleSystem smokeParticleSystem;
        private GameScreen ownerScreen;
        #endregion

        public SmokeBrick(GameScreen ownerScreen, Vector2 location, Texture2D itemTexture)
            : base(location, itemTexture)
        {
            this.ownerScreen = ownerScreen;
            Resistance = defaultResistance;
            smokeParticleSystem = new SmokePlumeParticleSystem(new Vector2(CollisionRect.Center.X, CollisionRect.Top - 100), 9);
            ownerScreen.AddParticleSystem(smokeParticleSystem);
        }

        /// <summary>
        /// Reset the brick to its default behaivour.
        /// </summary>
        public override void Reset()
        {
            base.Reset();
            Resistance = defaultResistance;
            currentTime = 0;
        }

        /// <summary>
        /// Controls the smoke effect by checking how long it has been active or unactive.
        /// </summary>
        private void HandleSmokeEffect(GameTime gameTime)
        {
            if (currentTime >= MAX_SMOKE_TIME)
            {
                timeIncFactor = -1;
                smokeParticleSystem.Active = false;
            }
            if (currentTime <= -MAX_SMOKE_TIME)
            {
                timeIncFactor = 1;
                smokeParticleSystem.Active = true;
            }

            currentTime += timeIncFactor * gameTime.ElapsedGameTime.Milliseconds;
        }

        /// <summary>
        /// Updates the brick.
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            HandleSmokeEffect(gameTime);
        }
    }
}
